package com.tarena.lbs.business.rpc;

import com.tarena.lbs.business.api.BusinessApi;
import com.tarena.lbs.business.api.pojo.BusinessDto;
import com.tarena.lbs.business.dao.repository.BusinessRepository;
import com.tarena.lbs.business.pojo.po.BusinessPO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;

@DubboService
public class BusinessApiImpl implements BusinessApi {

    @DubboReference
    private BusinessRepository businessRepository;

    @Override
    public BusinessDto getBusinessById(Integer businessId) {
        if (businessId == null) {
            return null;
        }
        
        // 查询数据库中的商家信息
        BusinessPO businessPO = businessRepository.getBusinessById(businessId);
        if (businessPO == null) {
            return null;
        }
        
        // 转换为DTO对象
        BusinessDto dto = new BusinessDto();
        BeanUtils.copyProperties(businessPO, dto);
        return dto;
    }

}
